#include "widget.h"
#include "ui_widget.h"

#include<QTimer>
#include<QDateTime>
#include<QDebug>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    QTimer*timer1=new QTimer(this);
    connect(ui->pushButton_begin,&QPushButton::clicked,[=](){
        timer1->start(1000);
    });

//    connect(timer1,&QTimer::timeout,[=](){
//        static int num=1;
//        ui->label->setText(QString::number(num++));
//    });

    connect(ui->pushButton_stop,&QPushButton::clicked,[=](){
        timer1->stop();
    });

    connect(timer1,&QTimer::timeout,this,&Widget::TimeUpDate);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::TimeUpDate()
{
    QString str=QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
    ui->label->setText(str);
}

